package com.mac.hosp_pre.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mac.hosp_pre.reply.R;
import com.mac.hosp_pre.user.model.req.UserInfoQueryReqDto;
import com.mac.hosp_pre.user.model.resp.UserRespDto;
import com.mac.hosp_pre.user.service.UserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Tag(name = "用户管理")
@RestController
@RequestMapping("/admin/user")
public class UserController {

    @Autowired
    private UserInfoService userInfoService;

    @Operation(summary = "用户列表（条件查询带分页）")
    @GetMapping("queryPage")
    public R queryPage(@ParameterObject UserInfoQueryReqDto userInfoQuery) {
        IPage<UserRespDto> respDtoIPage = userInfoService.selectPage(userInfoQuery);
        return R.success(respDtoIPage);
    }

    @Operation(summary = "用户锁定")
    @Parameters({
            @Parameter(name = "userId", description = "用户id", required = true),
            @Parameter(name = "status", description = "状态（0：锁定 1：正常）", required = true)
    })
    @GetMapping("lock/{userId}/{status}")
    public R lock(@PathVariable Long userId,@PathVariable Integer status) {
        userInfoService.lock(userId,status);
        return R.success();
    }

    @Operation(summary = "用户详情")
    @Parameter(name = "userId", description = "用户id", required = true)
    @GetMapping("detail/{userId}")
    public R detail(@PathVariable Long userId) {
        Map<String,Object> map = userInfoService.detail(userId);
        return R.success(map);
    }

    @Operation(summary = "用户认证审批")
    @Parameters({
            @Parameter(name = "userId", description = "用户id", required = true),
            @Parameter(name = "authStatus", description = "状态（0：未认证 1：认证中 2：认证成功 -1：认证失败）", required = true)
    })
    @GetMapping("approval/{userId}/{authStatus}")
    public R approval(@PathVariable Long userId,@PathVariable Integer authStatus) {
        userInfoService.approval(userId,authStatus);
        return R.success();
    }
}
